from codex import * from time import sleep import math import random CENTER = 120 display.fill(BLACK) display.draw_line(CENTER, 0, CENTER, 105, WHITE) display.draw_line(CENTER, 135, CENTER, 239, WHITE) display.draw_line(0, CENTER, 105, CENTER, WHITE) display.draw_line(135, CENTER, 239, CENTER, WHITE) x = CENTER y = CENTER angle = random.uniform(0, 2 * math.pi) angle_change_rate = 0.05 score = 0 max_score = 0 # Objectives: Get your circle to the exact center to get points. # If the circle touches the edge, game over. while True: val = accel.read() tilt_x = val[0] tilt_y = val[1] scaled_x = (tilt_x / 16384) scaled_y = (tilt_y / 16384) scaled_x = min(max(scaled_x, -1), 1) scaled_y = min(max(scaled_y, -1), 1) degrees_x = math.asin(scaled_x) * 180 / math.pi degrees_y = math.asin(scaled_y) * 180 / math.pi degrees_x = int(degrees_x) degrees_y = int(degrees_y) display.draw_circle(x, y, 15, BLACK) # Update the angle and direction over time angle += angle_change_rate if angle > 2 * math.pi: angle -= 2 * math.pi # Calculate the new position based on the updated angle x_offset = int(40 * math.cos(angle)) y_offset = int(40 * math.sin(angle)) x = degrees_x + CENTER + x_offset y = degrees_y + CENTER + y_offset display.draw_circle(x, y, 15, ORANGE) # Check if the circle is in the center and update the score if abs(x - CENTER) <= 1 and abs(y - CENTER) <= 1: score += 1 pixels.set(0, GREEN) pixels.set(1, GREEN) pixels.set(2, GREEN) pixels.set(3, GREEN) max_score = max(max_score, score) else: pixels.set(0, BLACK) pixels.set(1, BLACK) pixels.set(2, BLACK) pixels.set(3, BLACK) sleep(0.2) print(val[0]) if val[0] > 16000 or val[0] < -16000 or val[1] > 16000 or val[1] < -16000: display.clear() display.print("Game Over!") display.print("Your Score: " + str(max_score)) display.draw_circle(x, y, 15, WHITE)